#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	75338-nfs.sh
#Version:	1.1
#Date:		2013/11/20
#Author:	yuanhui.shi
#Email:		yuanhui.shi@cs2c.com.cn
#Summary:	02.04网络服务-05NFS-01字符模式-02添加共享目录-02添加主机为非法IP
#Notes:		NFS配置——添加主机为非法IP
#Copyright:	China Standard Software Co.,Ltd.
#History:
#		Version 1.0,2013/11/20
#		-The first one
#-----------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../../lib/Echo.sh
source ./lib/Ssh.sh
source ../../../lib/XmlParse.sh
source ./lib/cmd.sh

function CleanData ()
{
  EchoInfo "关闭服务器端的nfs服务，删除共享目录"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "command -v systemctl && /bin/systemctl stop nfs.service || /sbin/service nfs stop"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "rm -rf /nfs-test"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "echo '' >/etc/exports"
  EchoInfo "75338-nfs.sh执行完毕"
}
trap "CleanData" EXIT INT
if [ -z "$SFROOT" ]
then
    echo "SFROOT is null"
    exit 1
fi

DATA_DIR="${SFROOT}/testcases/Network_Service"
DATA_FILE="config.xml"

XmlParse ${DATA_DIR}/${DATA_FILE}

GetValue REHOST ReHost
GetValue RUSERNAME UserName
GetValue PASSWORD RootPasswd

USER=${RUSERNAME}
ServerIP=${REHOST}
PASSWORD=${PASSWORD}


#DATA_DIR="./data"
#DATA_FILE="75338-nfs.xml"
#
#XmlParse ${DATA_DIR}/${DATA_FILE}
#
#GetValue USER USER
#GetValue ServerIP ServerIP
#GetValue PASSWORD PASSWORD


#远程配置服务器
EchoInfo "远程配置服务器${ServerIP}"

Scp "${USER}" "${ServerIP}" "${PASSWORD}" "./nfs-config.sh" "/root/"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "sed -i s/*/1111.2222.3333.4444/g /root/nfs-config.sh"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "sh nfs-config.sh"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}"  "rm -rf /root/nfs-config.sh"

sleep 60

#当添加主机为非法IP时，检验客户端是否可以查看到nfs共享目录
EchoInfo "当NFS共享目录指定的主机为非法IP时，客户端是否可以查看到nfs共享目录"
stop_daemon iptables  

test -n "`showmount -e ${ServerIP} |grep /nfs-test/readonly`" -a -n "`showmount -e ${ServerIP} |grep /nfs-test/rw`" 
#showmount -e ${ServerIP} |grep /nfs-test/readonly && showmount -e ${ServerIP} |grep /nfs-test/rw

if [ $? -ne 0 ]; then
#   showmount -e ${ServerIP} | grep RPC
#   if [ $? -eq 0 ]; then
       echo "PASS | nfs共享目录清单为空"
#   else
#       echo "FAIL | nfs共享目录失败"
#       exit 1
 #  fi
else
   echo "FAIL | nfs共享目录清单不为空"
   exit 1
fi 

